package com.yxb.my_requests.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yxb.common.annotation.Log;
import com.yxb.common.core.controller.BaseController;
import com.yxb.common.core.domain.AjaxResult;
import com.yxb.common.enums.BusinessType;
import com.yxb.my_requests.domain.MyRequests;
import com.yxb.my_requests.service.IMyRequestsService;
import com.yxb.common.utils.poi.ExcelUtil;
import com.yxb.common.core.page.TableDataInfo;

/**
 * 我的发布Controller
 * 
 * @author 林德炫
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/my_requests/my_requests")
public class MyRequestsController extends BaseController
{
    @Autowired
    private IMyRequestsService myRequestsService;

    /**
     * 查询我的发布列表
     */
    @PreAuthorize("@ss.hasPermi('my_requests:my_requests:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyRequests myRequests)
    {
        startPage();
        List<MyRequests> list = myRequestsService.selectMyRequestsList(myRequests);
        return getDataTable(list);
    }

    /**
     * 导出我的发布列表
     */
    @PreAuthorize("@ss.hasPermi('my_requests:my_requests:export')")
    @Log(title = "我的发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyRequests myRequests)
    {
        List<MyRequests> list = myRequestsService.selectMyRequestsList(myRequests);
        ExcelUtil<MyRequests> util = new ExcelUtil<MyRequests>(MyRequests.class);
        util.exportExcel(response, list, "我的发布数据");
    }

    /**
     * 获取我的发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('my_requests:my_requests:query')")
    @GetMapping(value = "/{requestId}")
    public AjaxResult getInfo(@PathVariable("requestId") Long requestId)
    {
        return success(myRequestsService.selectMyRequestsByRequestId(requestId));
    }

    /**
     * 新增我的发布
     */
    @PreAuthorize("@ss.hasPermi('my_requests:my_requests:add')")
    @Log(title = "我的发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyRequests myRequests)
    {
        return toAjax(myRequestsService.insertMyRequests(myRequests));
    }

    /**
     * 修改我的发布
     */
    @PreAuthorize("@ss.hasPermi('my_requests:my_requests:edit')")
    @Log(title = "我的发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyRequests myRequests)
    {
        return toAjax(myRequestsService.updateMyRequests(myRequests));
    }

    /**
     * 删除我的发布
     */
    @PreAuthorize("@ss.hasPermi('my_requests:my_requests:remove')")
    @Log(title = "我的发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requestIds}")
    public AjaxResult remove(@PathVariable Long[] requestIds)
    {
        return toAjax(myRequestsService.deleteMyRequestsByRequestIds(requestIds));
    }
}
